﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<DTO.Models.MEDIA>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	CIT.COM.VN - LIÊN HỆ
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript" language="javascript">
        $.ajaxSetup({ dataType: "json", type: "POST", contentType: "application/json; charset=utf-8" });

        var randomNo1 = Math.floor(Math.random() * 11);
        var randomNo2 = Math.floor(Math.random() * 11);

        $(document).ready(function () {
            $("#no1").html(randomNo1);
            $("#no2").html(randomNo2);
        });

        function Cancel() {
            $("#name").val('');
            $("#email").val('');
            $("#content").val('');
        }

        function Validate() {
            // validate name
            var errorName = false;
            var errorNameMsg = "";
            var name = $("#name").val();
            if (name == '') {
                errorNameMsg = "Vui lòng nhập tên của bạn!";
                errorName = true;
            }

            // validate email
            var errorEmail = false;
            var errorEmailMsg = "";
            var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
            var email = $("#email").val();
            if (email == '') {
                errorEmailMsg = "Vui lòng nhập email của bạn!";
                errorEmail = true;
            }
            else if (!emailReg.test(email)) {
                errorEmailMsg = "Email không hợp lệ!";
                errorEmail = true;
            }

            // validate capcha
            var errorCapcha = false;
            var errorCapchaMsg = "";
            var answer = $("#capcha").val();
            if (answer != randomNo1 + randomNo2) {
                errorCapcha = true;
                errorCapchaMsg = "Câu trả lời không chính xác!";
            }

            if (errorName == true || errorEmail == true || errorCapcha == true) {
                $("#error-name").html(errorNameMsg);
                $("#error-email").html(errorEmailMsg);
                $("#error-capcha").html(errorCapchaMsg);
                return false;
            }
            else {
                $("#error-name").html('');
                $("#error-email").html('');
                $("#error-capcha").html('');
                return true;
            }
        }

        function Submit() {
            if (!Validate()) {
                randomNo1 = Math.floor(Math.random() * 11);
                randomNo2 = Math.floor(Math.random() * 11);
                $("#no1").html(randomNo1);
                $("#no2").html(randomNo2);
                return;
            }

            var url = "http://" + document.location.host;
            url += '<%= Url.Action("SaveFeedback") %>';
            var postData = '{"param":["' + $("#name").val() +
                '","' + $("#email").val() +
                '","' + $("#content").val() +
                '"]}';

            $.post(url,
                postData,
                function (data) {
                    if (data.mess == "success") {
                        alert("Gửi thông tin phản hồi thành công!");

                        $("#name").val('');
                        $("#email").val('');
                        $("#capcha").val('');
                        $("#content").val('');

                    }
                    else {
                        alert("Hệ thống xảy ra lỗi, vui lòng thử lại sau!");

                        randomNo1 = Math.floor(Math.random() * 11);
                        randomNo2 = Math.floor(Math.random() * 11);
                        $("#no1").html(randomNo1);
                        $("#no2").html(randomNo2);
                    }
                });

            $("#error-name").html('');
            $("#error-email").html('');
            $("#error-capcha").html('');
        }
    </script>


    <div class="dung-maincontent-show">
        <div class="dung-section">
            <div class="dung-section-border"></div>
            <div class="dung-section-title">LIÊN HỆ</div>
            <div class="dung-section-content">
                <div id="thong-tin-lien-he"><%= Model.Content %></div>
                <img src='<%= Url.Content("~/image/hinhphanchia.jpg")%>' alt="" width="680px" />
                <br />

                <div id="feedback">
                    <label><b>Tên:</b></label>
                    <br />
                    <input type="text" class="dung-textbox" id="name" name="name" size="50" maxlength="50" />
                    <span id="error-name" style="color:#FF0000"></span>

                    <br />
                    <label><b>Email:</b></label>
                    <br />
                    <input type="text" class="dung-textbox" id="email" name="email" size="50" maxlength="50" />
                    <span id="error-email" style="color:#FF0000"></span>

                    <br />
                    <label><b>Nội dung:</b></label>
                    <br />
                    <textarea id="content" name="content" class="dung-textbox" cols="80" rows="20"></textarea>
                    <br />

                    <div>Trả lời câu hỏi sau: 
                        <b><span id="no1"></span></b> + <b><span id="no2"></span></b> = ?
                    </div>
                    <input type="text" class="dung-textbox" id="capcha" name="capcha" size="2" maxlength="2" />
                    <span id="error-capcha" style="color:#FF0000"></span>
                    <br />
                    <br />

                    <input type="button" value="Phản hồi" class="dung-button-other" id="submit" onclick="Submit()"/>
                    <input type="button" value="Hủy bỏ" class="dung-button-other" id="cancel" onclick="Cancel()" />
                </div>
                <br />

                <img src='<%= Url.Content("~/image/hinhphanchia.jpg")%>' alt="" width="680px" />
                <br />

                <div>Vị trí công ty</div>
                <div id="map_canvas" style="width: 100%; height: 400px"></div>            
            </div>
        </div>
    </div>
    
    <div id="bao-test"></div>
</asp:Content>
